package com.changgou.service.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.changgou.service.system.dto.AdminMapper;
import com.changgou.service.system.service.AdminService;
import com.changgou.system.pojo.Admin;
import org.springframework.security.crypto.bcrypt.BCrypt;

import javax.annotation.Resource;

public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Resource
    private AdminMapper adminMapper;

    @Override
    public boolean login(Admin admin) {
        //根据登录名查询管理员
        //数据库查询出的对象
        Admin admin1 = this.lambdaQuery()
                .eq(Admin::getLoginName, admin.getLoginName())
                .eq(Admin::getStatus, 1)
                .one();
        if (admin1 == null) {
            return false;
        } else {
            //验证密码, Bcrypt为spring的包, 第一个参数为明文密码, 第二个参数为密文密码
            return BCrypt.checkpw(admin.getPassword(), admin1.getPassword());
        }
    }
}
